package com.xsqd.commons;

public class Result<T>{
    private Boolean flag;//用于描述当前这次请求是否成功了

    private Integer code;//返回给前端的业务状态码

    private String message;//用于描述本次请求的相关信息

    private T data;//真实返回给前端的数据

    public Boolean getFlag() {
        return flag;
    }

    public void setFlag(Boolean flag) {
        this.flag = flag;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static Result success(Integer code, String message, Object data){
        Result r = new Result<>();
        r.setFlag(true);
        r.setCode(code);
        r.setMessage(message);
        r.setData(data);
        return r;
    }

    public static Result fail(Integer code, String message){
        Result r = new Result<>();
        r.setFlag(false);
        r.setCode(code);
        r.setMessage(message);
        return r;
    }

}

